package com.lala.service.impl;

import com.lala.dao.OrderDetailsDao;
import com.lala.entity.OrderDetails;
import com.lala.service.OrderDetailsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (OrderDetails)表服务实现类
 *
 * @author lixu
 * @since 2020-03-24 09:43:32
 */
@Service("orderDetailsService")
public class OrderDetailsServiceImpl implements OrderDetailsService {
    @Resource
    private OrderDetailsDao orderDetailsDao;

    /**
     * @ClassName OrderDetailsServiceImpl
     * @Description : 根据id查询订单详情
     *
     * @param id
     * @Return : com.lala.entity.OrderDetails
     * @Author : lixu
     * @Date : 2020/3/25 17:01
    */
    @Override
    public OrderDetails queryById(Integer id) {
        return this.orderDetailsDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<OrderDetails> queryAllByLimit(int offset, int limit) {
        return this.orderDetailsDao.queryAllByLimit(offset, limit);
    }

    /**
     * @ClassName OrderDetailsServiceImpl
     * @Description : 订单添加详情
     *
     * @param orderDetails
     * @Return : com.lala.entity.OrderDetails
     * @Author : lixu
     * @Date : 2020/3/25 17:03
    */
    @Override
    public OrderDetails save(OrderDetails orderDetails) {

        //根据距离等计算价钱，每公里10元。
        double price=orderDetails.getDistance()*10;
        if (orderDetails.getFragile()!=null){
            price+=500;
        }if(orderDetails.getExtra()!=null){
            price+=1000;
        }
            orderDetails.setOrderPrice(price);

        this.orderDetailsDao.save(orderDetails);
        return orderDetails;
    }

    /**
     * @ClassName OrderDetailsServiceImpl
     * @Description : 修改订单详情
     *
     * @param orderDetails
     * @Return : com.lala.entity.OrderDetails
     * @Author : lixu
     * @Date : 2020/3/25 17:49
    */
    @Override
    public int update(OrderDetails orderDetails) {
        return this.orderDetailsDao.update(orderDetails);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.orderDetailsDao.deleteById(id) > 0;
    }

    @Override
    public List<OrderDetails> selectAll() {
        return orderDetailsDao.selectAll();
    }
}